home *** CD-ROM | disk | FTP | other *** search
- /* file: balls.c */
- /* by Dan Gilliam */
-
- #include "busybox.h"
-
- static Rect innerRect;
- static Rect ballRect;
- static Point deltaPt; /* stores our movement offset */
- static Point lastPt; /* stores our, uh, last point. */
-
- #define ballRadius 3
-
-
- void InitSillyBallz(Rect *drawArea, int16 objectID) {
- /* set-up stuff */
-
- innerRect = *drawArea;
- innerRect.top += ballRadius + 2;
- innerRect.left += ballRadius + 2;
- InsetRect(&innerRect, ballRadius, ballRadius);
-
- SetRect(&ballRect, -ballRadius, -ballRadius, ballRadius, ballRadius); /* set center of ball to 0,0 */
- deltaPt.h = 2 * ballRadius; /* get an initial direction and speed*/
- deltaPt.v = 2 * ballRadius;
- lastPt.h = innerRect.right/2;
- lastPt.v = innerRect.bottom/2;
-
- OffsetRect(&ballRect, lastPt.h, lastPt.v); /* move ballRect to the pt */
-
- } /* InitSillyBallz */
-
-
- void DrawSillyBallz ( int16 objectID) {
- /* do the bouncing ball */
-
- Point newCenter;
-
-
- AddPt(deltaPt, &lastPt); /* calculate where we're going*/
- if ((lastPt.h < innerRect.left) || (lastPt.h > innerRect.right))
- deltaPt.h = -deltaPt.h + (Random() % 2);
-
- if ((lastPt.v > innerRect.bottom) || (lastPt.v < innerRect.top))
- deltaPt.v = -deltaPt.v + (Random() % 2);
-
-
- EraseOval(&ballRect);
- OffsetRect(&ballRect, deltaPt.h, deltaPt.v);
- PaintOval(&ballRect);
-
- } /* DoSillyBallz */
-